const { param } = require('../routes')

//数据层
module.exports=class testModel extends require('./Model'){

    //查找
    static findTestList(req,res){
        return new Promise((resolve,reject)=>{
            let sql='select*from emp'
            this.query(sql)
            .then((result)=>{
                resolve(result)
            })
            .catch((error)=>{
             reject(error)
            }
            )
        })
    }



    //增加
    static addTestList(req,res){
        return new Promise((resolve,reject)=>{
            let params=req.body
            let sql='insert into emp set?'
            this.query(sql,params)
            .then((result)=>{
                resolve({status:200,message:"success",other:result})
            })
            .catch((error)=>{
             reject( resolve({status:200,message:"success",other:result}))
            }
            )
        })
    }





    //删除单个
    static deleteTestList(req,res){
        return new Promise((resolve,reject)=>{
            let params=req.body
            let sql='DELETE FROM emp WHERE id=?'
            this.query(sql,params)
            .then((result)=>{
                resolve({status:200,message:"id为"+id+"删除成功"})
            })
            .catch((error)=>{
             reject( resolve({status:200,message:"id为"+id+"删除失败"}))
            }
            )
        })
    }




    //删除多个



    //修改
    static changeTest(req,res){
        return new Promise((resolve,reject)=>{
            let {name,newNmae}=req.body
            let sql='update emp set name=? where name=?'
            this.query(sql,[newName,name])
            .then((result)=>{
                resolve({status:200,message:"name为"+name+"成功修改为"+newNmae})
            })
            .catch((error)=>{
             reject( resolve({status:200,message:"name为"+name+"修改为"+newNmae+"失败"}))
            }
            )
        })
    }




}